﻿
@{
    ViewData["Title"] = "网站头部广告内容设置";
    var list = ViewData["list"] as List<site_layout_content>;
    var users = ViewData["users"] as List<WqUser>;
    ViewData["container-css"] = "col-lg-12";
}

<div class="row">
    <div class="col-md-12">
        <ul id="tab-list" class="nav nav-tabs" role="tablist">
            <li class="active"><a href="#@AD_Postion.Top" role="tab" data-toggle="tab">顶部</a></li>
            <li><a href="#@AD_Postion.Head" role="tab" data-toggle="tab">中间</a></li>
            <li><a href="#@AD_Postion.Banner_Left" role="tab" data-toggle="tab">左侧</a></li>
            <li><a href="#@AD_Postion.Banner_Right" role="tab" data-toggle="tab">右侧</a></li>
            <li><a href="#@AD_Postion.Bottom" role="tab" data-toggle="tab">底部</a></li>
        </ul>

        <div class="margin-top-10"></div>

        <div id="tab-content" class="tab-content">
            <div class="tab-pane active" id="@AD_Postion.Top">
                @{
                    var top = list.Where(x => x.position == AD_Postion.Top).SingleOrDefault() ?? new site_layout_content();
                    var userTop = users.Where(x => x.Id == top.uid).SingleOrDefault() ?? new WqUser();
                    if (string.IsNullOrWhiteSpace(top.content))
                    {
                        top.content = "<span style=\"color:#BCAC98;\" class=\"btn-sm\">生辰八字算命-周易命理预测 | 阴阳五行八卦研究 | 八字合婚配对查询</span>";
                    }

                    <div class="row">
                        <form id="ajaxForm@(nameof(AD_Postion.Top).ToLower())" enctype="multipart/form-data" class="form-horizontal">
                            <input type="hidden" asp-for="@top.id" name="id" />
                            <input type="hidden" name="position" value="@(AD_Postion.Top)" />
                            <div class="container-fluid">
                                <div class="row form-group">
                                    <label class="control-label col-md-1">位置</label>
                                    <div class="col-md-11">
                                        <select class="form-control" disabled>
                                            <option value="@(AD_Postion.Top)" selected>顶部</option>
                                            <option value="@(AD_Postion.Head)">中间</option>
                                            <option value="@(AD_Postion.Banner_Left)">左侧</option>
                                            <option value="@(AD_Postion.Banner_Right)">右侧</option>
                                            <option value="@(AD_Postion.Bottom)">底部</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">内容</label>
                                    <div class="col-md-11">
                                        <div id="editor-top">
                                            @Html.Raw(top.content)
                                        </div>
                                        <div class="row text-info">
                                            <div class="col-md-11">
                                                建议内容高度不超过100px; 宽度为1000px-1200px之间,否则可能会导致布局不够美观
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改人</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" asp-for="@(userTop.NickName)" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">创建时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@top.create_time.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@top.last_update.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-6 col-md-offset-1">
                                        <button type="button" class="btn btn-primary" onclick="SaveArticle('@nameof(AD_Postion.Top).ToLower()')">保存</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                }
            </div>

            <div class="tab-pane" id="@AD_Postion.Head">
                @{
                    var head = list.Where(x => x.position == AD_Postion.Head).SingleOrDefault() ?? new site_layout_content();
                    var userHeader = users.Where(x => x.Id == head.uid).SingleOrDefault() ?? new WqUser();
                    if (string.IsNullOrWhiteSpace(head.content))
                    {
                        head.content = "<div class=\"row\"><div class=\"col-md-6\" style=\"background-color:#EAE2D5;height:64px;\"><img src=\"/imgs/title.png\" title=\"魏清八字风水算命论坛\" height=\"60\"></div><div class=\"col-md-6\" style=\"background-color:#EAE2D5;height:64px;\">欢迎加入算命风水相术中医交流群: 372417319<a target=\"_blank\" href=\"//shang.qq.com/wpa/qunwpa?idkey=102983be9cfa6dc4b4e22a6fcfa8f67dda93e3bdeffdae8aaead089c1295c240\"><img border=\"0\" src=\"//pub.idqqimg.com/wpa/images/group.png\" alt=\"算命风水相术中医\" title=\"算命风水相术中医\"></a>,八字、算命、风水堪舆、手面相、择日取名、六爻八卦、壬遁太乙、相法星象专业预测群，由群主清清流水——魏清每天坐堂免费预测，欢迎问测者加入！</div></div>";
                    }

                    <div class="row">
                        <form id="ajaxForm@(nameof(AD_Postion.Head).ToLower())" enctype="multipart/form-data" class="form-horizontal">
                            <input type="hidden" asp-for="@head.id" name="id" />
                            <input type="hidden" name="position" value="@(AD_Postion.Head)" />
                            <div class="container-fluid">
                                <div class="row form-group">
                                    <label class="control-label col-md-1">位置</label>
                                    <div class="col-md-11">
                                        <select class="form-control" disabled>
                                            <option value="@(AD_Postion.Top)">顶部</option>
                                            <option value="@(AD_Postion.Head)" selected>中间</option>
                                            <option value="@(AD_Postion.Banner_Left)">左侧</option>
                                            <option value="@(AD_Postion.Banner_Right)">右侧</option>
                                            <option value="@(AD_Postion.Bottom)">底部</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">内容</label>
                                    <div class="col-md-11">
                                        <div id="editor-header">
                                            @Html.Raw(head.content)
                                        </div>
                                        <div class="row text-info">
                                            <div class="col-md-11">
                                                建议内容高度不超过100px; 宽度为1000px-1200px之间,否则可能会导致布局不够美观
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改人</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" asp-for="@(userHeader.NickName)" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">创建时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@head.create_time.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@head.last_update.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-6 col-md-offset-1">
                                        <button type="button" class="btn btn-primary" onclick="SaveArticle('@nameof(AD_Postion.Head).ToLower()')">保存</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                }
            </div>
            <div class="tab-pane" id="@AD_Postion.Banner_Left">
                @{
                    var banner_left = list.Where(x => x.position == AD_Postion.Banner_Left).SingleOrDefault() ?? new site_layout_content();
                    var userLeft = users.Where(x => x.Id == banner_left.uid).SingleOrDefault() ?? new WqUser();
                    if (string.IsNullOrWhiteSpace(banner_left.content))
                    {
                        banner_left.content = "<div class=\"col-lg-8\" style=\"background-color:#F3ECE2;\"> <div class=\"row\"> <div class=\"col-md-1\"> <img src=\"/imgs/weixin.jpg\" height=\"40\"> </div> <div class=\"col-md-8\"> <div class=\"row\"> <div class=\"col-md-6\"> 站长亲测<br><span style=\"font-size:14px;\">微信号:383129257</span> </div> <div class=\"col-md-6\"> <div style=\"height:40px;line-height:40px;\"> 八字详批:198元 </div> </div> </div> </div> <div class=\"col-md-1\"> <img src=\"/imgs/mfycgq.png\" height=\"40\"> </div> </div></div>";
                    }

                    <div class="row">
                        <form id="ajaxForm@(nameof(AD_Postion.Banner_Left).ToLower())" enctype="multipart/form-data" class="form-horizontal">
                            <input type="hidden" asp-for="@banner_left.id" name="id" />
                            <input type="hidden" name="position" value="@(AD_Postion.Banner_Left)" />
                            <div class="container-fluid">
                                <div class="row form-group">
                                    <label class="control-label col-md-1">位置</label>
                                    <div class="col-md-11">
                                        <select class="form-control" disabled>
                                            <option value="@(AD_Postion.Top)">顶部</option>
                                            <option value="@(AD_Postion.Head)">中间</option>
                                            <option value="@(AD_Postion.Banner_Left)" selected>左侧</option>
                                            <option value="@(AD_Postion.Banner_Right)">右侧</option>
                                            <option value="@(AD_Postion.Bottom)">底部</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">内容</label>
                                    <div class="col-md-11">
                                        <div id="editor-left">
                                            @Html.Raw(banner_left.content)
                                        </div>
                                        <div class="row text-info">
                                            <div class="col-md-11">
                                                建议内容高度不超过100px; 宽度为800px左右,否则可能会导致布局不够美观
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改人</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" asp-for="@userLeft.NickName" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">创建时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@banner_left.create_time.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@banner_left.last_update.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-6 col-md-offset-1">
                                        <button type="button" class="btn btn-primary" onclick="SaveArticle('@nameof(AD_Postion.Banner_Left).ToLower()')">保存</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                }
            </div>
            <div class="tab-pane" id="@AD_Postion.Banner_Right">
                @{
                    var banner_right = list.Where(x => x.position == AD_Postion.Banner_Right).SingleOrDefault() ?? new site_layout_content();
                    var userRight = users.Where(x => x.Id == banner_right.uid).SingleOrDefault() ?? new WqUser();
                    if (string.IsNullOrWhiteSpace(banner_right.content))
                    {
                        banner_right.content = "<div class=\"col-lg-4\"> <div style=\"height:40px;width:80px;float:left;\"> <img src=\"/imgs/weixin.jpg\" height=\"40\"> </div> <div class=\"bgyc\"> 六爻预测<br>每卦66元 </div> </div>";
                    }

                    <div class="row">
                        <form id="ajaxForm@(nameof(AD_Postion.Banner_Right).ToLower())" enctype="multipart/form-data" class="form-horizontal">
                            <input type="hidden" asp-for="@banner_right.id" name="id" />
                            <input type="hidden" name="position" value="@(AD_Postion.Banner_Right)" />
                            <div class="container-fluid">
                                <div class="row form-group">
                                    <label class="control-label col-md-1">位置</label>
                                    <div class="col-md-11">
                                        <select class="form-control" disabled>
                                            <option value="@(AD_Postion.Top)">顶部</option>
                                            <option value="@(AD_Postion.Head)">中间</option>
                                            <option value="@(AD_Postion.Banner_Left)">左侧</option>
                                            <option value="@(AD_Postion.Banner_Right)" selected>右侧</option>
                                            <option value="@(AD_Postion.Bottom)">底部</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">内容</label>
                                    <div class="col-md-11">
                                        <div id="editor-right">
                                            @Html.Raw(banner_right.content)
                                        </div>
                                        <div class="row text-info">
                                            <div class="col-md-11">
                                                建议内容高度不超过100px; 宽度为400px左右,否则可能会导致布局不够美观
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改人</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" asp-for="@(userRight.NickName)" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">创建时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@banner_right.create_time.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@banner_right.last_update.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-6 col-md-offset-1">
                                        <button type="button" class="btn btn-primary" onclick="SaveArticle('@nameof(AD_Postion.Banner_Right).ToLower()')">保存</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                }
            </div>
            <div id="@AD_Postion.Bottom" class="tab-pane">
                @{
                    var bottom = list.Where(x => x.position == AD_Postion.Bottom).SingleOrDefault() ?? new site_layout_content();
                    var userBottom = users.Where(x => x.Id == bottom.uid).SingleOrDefault() ?? new WqUser();
                    if (string.IsNullOrWhiteSpace(bottom.content))
                    {
                        bottom.content = "<div id=\"foot\" style=\"height:32px;background-color:#643420;width:100%;text-align:center;line-height:32px;color:#ccc;font-size:10px;\"> <div align=\"center\"><text>power by QQ 694060865<text>  <a style=\"color:#666\" href=\"http://www.miibeian.gov.cn\" ;=\"\" target=\"_blank\">湘ICP备17007745号</a></text></text></div> </div>";
                    }

                    <div class="row">
                        <form id="ajaxForm@(nameof(AD_Postion.Bottom).ToLower())" enctype="multipart/form-data" class="form-horizontal">
                            <input type="hidden" asp-for="@bottom.id" name="id" />
                            <input type="hidden" name="position" value="@(AD_Postion.Bottom)" />
                            <div class="container-fluid">
                                <div class="row form-group">
                                    <label class="control-label col-md-1">位置</label>
                                    <div class="col-md-11">
                                        <select class="form-control" disabled>
                                            <option value="@(AD_Postion.Top)">顶部</option>
                                            <option value="@(AD_Postion.Head)">中间</option>
                                            <option value="@(AD_Postion.Banner_Left)">左侧</option>
                                            <option value="@(AD_Postion.Banner_Right)">右侧</option>
                                            <option value="@(AD_Postion.Bottom)" selected>底部</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">内容</label>
                                    <div class="col-md-11">
                                        <div id="editor-bottom">
                                            @Html.Raw(bottom.content)
                                        </div>
                                        <div class="row text-info">
                                            <div class="col-md-11">
                                                建议内容高度不超过50px; 宽度为1200px左右,否则可能会导致布局不够美观
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改人</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" asp-for="@(userBottom.NickName)" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">创建时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@bottom.create_time.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <label class="control-label col-md-1">修改时间</label>
                                    <div class="col-md-11">
                                        <input class="form-control" type="text" value="@bottom.last_update.ToLocalDateTimeString()" />
                                    </div>
                                </div>
                                <div class="row form-group">
                                    <div class="col-md-6 col-md-offset-1">
                                        <button type="button" class="btn btn-primary" onclick="SaveArticle('@nameof(AD_Postion.Bottom).ToLower()')">保存</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                }
            </div>
        </div>
    </div>
</div>

@section scripts{

    <script type="text/javascript">
        var E = window.wangEditor
        var editorHeader = new E('#editor-header')
        // 或者 var editorHeader = new E( document.getElementById('editor') )
        // editorHeader.customConfig.uploadImgShowBase64 = true
        // 将图片大小限制为 3M
        editorHeader.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
        editorHeader.customConfig.uploadImgServer = '/upload/image'
        // 限制一次最多上传 5 张图片
        editorHeader.customConfig.uploadImgMaxLength = 5
        editorHeader.customConfig.uploadFileName = 'image'
        editorHeader.create();

        var editorLeft = new E('#editor-left')
        editorLeft.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
        editorLeft.customConfig.uploadImgServer = '/upload/image'
        editorLeft.customConfig.uploadImgMaxLength = 5
        editorLeft.customConfig.uploadFileName = 'image'
        editorLeft.create();

        var editorRight = new E('#editor-right')
        editorRight.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
        editorRight.customConfig.uploadImgServer = '/upload/image'
        editorRight.customConfig.uploadImgMaxLength = 5
        editorRight.customConfig.uploadFileName = 'image'
        editorRight.create();

        var editorBottom = new E('#editor-bottom')
        editorBottom.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
        editorBottom.customConfig.uploadImgServer = '/upload/image'
        editorBottom.customConfig.uploadImgMaxLength = 5
        editorBottom.customConfig.uploadFileName = 'image'
        editorBottom.create();

        var editorTop = new E('#editor-top')
        editorTop.customConfig.uploadImgMaxSize = 3 * 1024 * 1024
        editorTop.customConfig.uploadImgServer = '/upload/image'
        editorTop.customConfig.uploadImgMaxLength = 5
        editorTop.customConfig.uploadFileName = 'image'
        editorTop.create();

        E.fullscreen.init(editorHeader);
        E.viewSource.init(editorHeader);

        E.fullscreen.init(editorLeft);
        E.viewSource.init(editorLeft);

        E.fullscreen.init(editorRight);
        E.viewSource.init(editorRight);

        E.fullscreen.init(editorBottom);
        E.viewSource.init(editorBottom);

        E.fullscreen.init(editorTop);
        E.viewSource.init(editorTop);

        function SaveArticle(id) {
            var textContent = '';
            if (id == '@nameof(AD_Postion.Head).ToLower()') {
                textContent = editorHeader.txt.text();
            } else if (id == '@nameof(AD_Postion.Banner_Left).ToLower()') {
                textContent = editorLeft.txt.text();
            } else if (id == '@nameof(AD_Postion.Banner_Right).ToLower()') {
                textContent = editorRight.txt.text();
            }else if (id == '@nameof(AD_Postion.Bottom).ToLower()') {
                textContent = editorBottom.txt.text();
            }else if (id == '@nameof(AD_Postion.Top).ToLower()') {
                textContent = editorTop.txt.text();
            }

            if (textContent.length === 0) {
                utils.ShowError("请输入文章内容");
                return;
            }

            var htmlContent = '';
            if (id == '@nameof(AD_Postion.Head).ToLower()') {
                htmlContent = editorHeader.txt.html();
            } else if (id == '@nameof(AD_Postion.Banner_Left).ToLower()') {
                htmlContent = editorLeft.txt.html();
            }else if (id == '@nameof(AD_Postion.Banner_Right).ToLower()') {
                htmlContent = editorRight.txt.html();
            }else if (id == '@nameof(AD_Postion.Bottom).ToLower()') {
                htmlContent = editorBottom.txt.html();
            }else if (id == '@nameof(AD_Postion.Top).ToLower()') {
                htmlContent = editorTop.txt.html();
            }


            $("#ajaxForm" + id).ajaxSubmit({
                type: 'post',
                url: '@Url.Action("Update")',
                data: {
                    content: htmlContent
                },  // data是作为额外提交的表单数据
                success: function (e) {
                    if (e.msg == 'ok') {
                        utils.ShowSuccess(e.data, function () {
                            location.reload(true);
                        });
                    }
                },
                error: function (e) {
                    utils.ShowError(e.data);
                }
            });
        }
    </script>
}